<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <script>
    window.onload=function (){
      let aBtn=document.getElementsByTagName('input');

      for(let i=0;i<aBtn.length;i++){
        aBtn[i].onclick=function (){
          alert(i);
        };
      }
    };
    </script>
  </head>
  <body>
    <input type="button" value="1">
    <input type="button" value="2">
    <input type="button" value="3">
  </body>
</html>
